package object.library.operation;

import object.library.Book;
import object.library.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("删除书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要删除的书籍序号：");
        int index = scanner.nextInt();
        if(index < 1 || index >= bookList.getSize()){
            System.out.println("输入的序号超出范围！");
            return;
        }
        if(index == bookList.getSize() - 1){
            bookList.setSize(bookList.getSize() - 1);
        }else{
            Book lastBook = bookList.getBook(bookList.getSize() - 1);
            bookList.setBook(index, lastBook);
            bookList.setSize(bookList.getSize() - 1);
        }
        System.out.println("删除成功！");
    }
}
